<?php
// +----------------------------------------------------------------------
// | Citrix [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.tpCitrix.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.tpCitrix.com/ )
// +----------------------------------------------------------------------
// | Author: Citrix < 2722279500@qq.com >
// +----------------------------------------------------------------------

namespace app\index\controller;

use \think\Db;
use \think\Cache;
use \think\Cookie;
use \think\Session;
use app\index\controller\Base;
class Article extends Base
{
	public function __construct()
    {
        parent::__construct();
        $this->assign('cur',"article");
        $cate_model = Db::name('article_cate');
        $article_cate = $cate_model->where('pid',0)->order('sort DESC')->select();
        if(!empty($article_cate))
        {
          foreach ($article_cate as $k => $v) 
          {
            $article_cate[$k]['cate2'] = $cate_model->where('pid',$article_cate[$k]['id'])->order('sort DESC')->select();
            if(!empty($article_cate[$k]['cate2']))
            {
              foreach ($article_cate[$k]['cate2'] as $key => $value) 
              {
                $article_cate[$k]['cate2'][$key]['cate3'] = $cate_model->where('pid',$article_cate[$k]['cate2'][$key]['id'])->order('sort DESC')->select();
              }
            }
          }
        }
        $this->article_cate = $article_cate;
        $this->assign('article_cate',$article_cate);
    }
    public function index()
    {
        $cate_id = input('cate_id/d',$this->article_cate[0]['id']);
        $count = Db::name('article')->where(['status'=>1,'article_cate_id'=>$cate_id])->count();
        $article = Db::name('article')->where(['status'=>1,'article_cate_id'=>$cate_id])->order('sort DESC')->select();
        $this->assign('article',$article);
        $this->assign('cate_id',$cate_id);
      $this->assign('web_title',get_article_cate_name($cate_id).'-资讯中心');
        return $this->fetch();
    }
    public function info()
    {
        $id = input('id/d',0);
        $cate_id = input('cate_id/d',$this->article_cate[0]['id']);
        $info = Db::name('article')->where('id',$id)->find();
        if(!empty($info))
        {
            $click = $info['click']+1;
            Db::name('article')->where('id',$id)->update(['click'=>$click]);
        }
        $last = Db::name('article')->where(['article_cate_id'=>$cate_id])->where('id','lt',$id)->find();
        $next = Db::name('article')->where(['article_cate_id'=>$cate_id])->where('id','gt',$id)->find();

        $this->assign('info',$info);
        $this->assign('last',$last);
        $this->assign('next',$next);
        $this->assign('web_title',$info['title'].'-'.get_article_cate_name($cate_id).'-资讯中心');
        $this->assign('cate_id',$cate_id);
        return $this->fetch();
    }
}